package travelDream.beans;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import traveldream.ejb.DTO.ExcursionDTO;
import traveldream.ejb.interfaces.*;

@ManagedBean(name = "ExcursionEditManaged")
@ViewScoped
public class ExcursionEditManaged {

	private ExcursionDTO eDTO;
	private boolean notPrima = false;
	@EJB
	ExcursionEditBeanLocal ExcursionEditBeanLocal;
	
	public ExcursionEditManaged(){
	}
	
	public void loadExcursion(){
		if(notPrima == false){
			FacesContext facesContext = FacesContext.getCurrentInstance();
			int passedParameter = Integer.parseInt((facesContext.getExternalContext().getRequestParameterMap().get("id")));
			try{
			eDTO = ExcursionEditBeanLocal.find(passedParameter);
			}
			catch(NotFindException e){
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info", "No excursion founded. Please, go back with the menu and try again!!"));
				return;
			}
			notPrima = true;
		}
	}
	public String update(){
		ExcursionEditBeanLocal.update(eDTO);
		return "excursion.xhtml?faces-redirect=true";
	}

	public ExcursionDTO geteDTO() {
		return eDTO;
	}

	public void seteDTO(ExcursionDTO eDTO) {
		this.eDTO = eDTO;
	}

	public ExcursionEditBeanLocal getExcursionEditBeanLocal() {
		return ExcursionEditBeanLocal;
	}

	public void setExcursionEditBeanLocal(ExcursionEditBeanLocal ExcursionEditBeanLocal) {
		ExcursionEditBeanLocal = ExcursionEditBeanLocal;
	}
	
}